/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef _SCRIPTFACTORY_H_
#define _SCRIPTFACTORY_H_

#include "IScript.h"
#include "ScriptFactory.h"
#include <map>
#include <string>

class ScriptFactory
{
private:
	static ScriptFactory                * _instance;
	static std::map<std::string, void*> * _creationHandlers;
private:
	ScriptFactory();
	ScriptFactory(const ScriptFactory & other);
	~ScriptFactory();
	ScriptFactory & operator=(const ScriptFactory & other);
public:
	static ScriptFactory * instance();
	static void addScriptType(const char * name, IScript * (*func)());
	IScript * scriptFromFile(const char * type, const char * path);
	IScript * scriptFromString(const char * type, const char * code);
	static std::map<std::string, void*> * createHandlersMap();
public:
	class ScriptType
	{
	public:
		ScriptType(const char * name, IScript * (*func)())
		{
			ScriptFactory::addScriptType(name, func);
		}
	};
};

#define registerScriptType(name, type)  IScript * createNewScriptInstance_##type(){return new type();}\
										ScriptFactory::ScriptType script_type_##type(name, createNewScriptInstance_##type);

#endif